#ifndef SERIALFORM_H
#define SERIALFORM_H

#include <QWidget>

namespace Ui {
class SerialForm;
}

class SerialForm : public QWidget
{
    Q_OBJECT

public:
    explicit SerialForm(QWidget *parent = 0);
    ~SerialForm();

signals:
    void SignalSerialOpen(const QString&, quint32, quint8);
    void SignalSerialClose();
    void SignalUpdate(const QByteArray&, quint16, bool);
    void SignalUpdateStop();
    void SignalUpdateExecute();

    void SignalSerialWriteHex(const QByteArray&);
    void SignalSerialWriteStr(const QString&);

private slots:
    void on_serialOperationBtn_clicked();

    void on_refreshSerialButton_clicked();

    void on_fireFileOpenBtn_clicked();

    void on_startUpdateBtn_clicked();

private slots:
    void SlotUpdateProgress(int);
    void SlotSerialError(void);
    void SlotUpdateTips(const QString &, quint8);
    void SlotRecvSerialLog(const QString&);

    void on_clearLogBtn_clicked();

    void on_updateStopBtn_clicked();

    void on_resetBtn_clicked();

    void on_crcCheckBtn_clicked();

    void on_serialSendBtn_clicked();

    void on_serialEnterSendBtn_clicked();

    void on_shellBtn_clicked();

private:
    bool m_SerialIsOpen = false;
    bool m_UpdateIsRun = false;

    void RefreshSerialPort();
    bool checkHexStr(QString&, bool);

    int hexStrToChar(char);
    QByteArray hexStrToByteArray(const QString&);
    QString byteArrayToHexStr(const QByteArray &);

    QVector<QString> m_PortName;

private:
    Ui::SerialForm *ui;
};

#endif // SERIALFORM_H
